import javax.swing.*;
import java.awt.event.*;

public class JoinDialog extends JDialog{
	CardClient main;
	
	JTextField hostTxt = new JTextField();
  	JTextField nameTxt = new JTextField();
  	JLabel serverLabel  =  new JLabel("服务器名：");
  	JLabel userNameLabel=  new JLabel("  玩家名：");
	JButton ok=new JButton("确定");
	JPanel pane;

    public JoinDialog(CardClient main) {
    	super(main,"加入游戏",true);
    	this.main=main;
    	setSize(400,200);
    	setResizable(false);
    	setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    	init();
    }
    
 private void init(){
 	pane=(JPanel)getContentPane();
 	serverLabel.setBounds(40,20,100,25);
 	userNameLabel.setBounds(40,60,100,25);
 	hostTxt.setBounds(150,20,100,25);
 	nameTxt.setBounds(150,60,100,25);
 	
 	ok.setBounds(170,100,100,40);
 	hostTxt.setText("localhost");
 	nameTxt.setText(System.getProperty("user.name"));
 	pane.setLayout(null);
 	pane.add(serverLabel,null);
 	pane.add(userNameLabel,null);
 	pane.add(hostTxt,null);
    pane.add(nameTxt,null); 
    ok.addActionListener(new java.awt.event.ActionListener(){
	public void actionPerformed(ActionEvent e){
		main.setHost(hostTxt.getText());
		main.setName(nameTxt.getText());
		//main.joinGame(main.getHost(),main.getPort());
		dispose();
	}
	});

    pane.add(ok,null);	
 	}  
}